#!/bin/sh

#validé
# arguments  :
# 1 : url de l'instance
# 2 : url ldap
# 3 : mot de passe ldap
# 4 : pwd
# 5 : storage
# 6 : user

echo "Installation de java ..."
if [ -f /usr/bin/apt-get ]
then
  echo "Debian like system detected"
  sudo apt-get update -qq
  sudo apt-get install -y -qq ant openjdk-6-jdk > /dev/null
else
  echo "RedHat like system detected"
  sudo yum check-update -y -q
  sudo yum install -y -q  ant openjdk-6-jdk > /dev/null
fi

echo "url=$1" > instance.properties
echo "deploy.goal=$2" >> instance.properties
echo "ldap.host=$3" >> instance.properties
echo "ldap.password=$4" >> instance.properties
echo "storage.url=$5" >> instance.properties
echo "deploy.username=$6" >> instance.properties

echo "donnée recues :"
cat instance.properties

echo "ldap.port=389" >> instance.properties
echo "ldap.binddn=cn=Manager,dc=gicom,dc=org" >> instance.properties
echo "ssh.KeyFile=~/id_rsa-pstam-keypair" >> instance.properties

mkdir script

echo "récupération de antLDAP et de unbounded"
mkdir lib
wget -nv  $5/lib/com.soluvas.antldap-1.1.0.jar 
mv com.soluvas.antldap-1.1.0.jar lib
wget -nv  $5/lib/unboundid-ldapsdk-se.jar 
mv unboundid-ldapsdk-se.jar lib
echo "démarage de bootstrap.xml"
ant -f bootstrap.xml startInstance
